var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    orderlist: [],
    currentTabsIndex: 2,
    now_page: 1
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getdoing(4);
  },
  // 获取进行中数据
  getdoing: function (type) {
    var that = this;
    var shopid = wx.getStorageSync("shop_id");
    var param = {
      url: "api/shop/grabOrders",
      data: {
        shop_id: shopid,
        now_page:1,
        type: type
      },
      success: function (e) {
        console.log(e)
        var order = e.data.data.list;
        
        that.setData({
          orderlist: order
        })
      },
    };
    app.post(param);
  },
 

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  // 播放录音
  luyinplay: function (e) {
    var myaudio = wx.createInnerAudioContext();
    var src = e.currentTarget.dataset.src;
    var index = e.currentTarget.dataset.index;
    var orderlist = this.data.orderlist;
    var playing = orderlist[index].playing;
    if (playing == false) {
      myaudio.play();
      playing = true;
      this.setData({
        orderlist: orderlist
      })
      myaudio.onEnded(() => {
        playing = false
        this.setData({
          orderlist: orderlist
        })
      })
    } else {
      myaudio.play();
      playing = false;
      this.setData({
        orderlist: orderlist
      })
    }

  },

  onReachBottom: function () {
    var that = this;
    // 显示加载图标
    
    // 页数+1
    var now_page = parseInt(that.data.now_page)+1;
    if (now_page > parseInt(that.data.totalpage)) {
      wx.showToast({
        title: '没有更多数据了',
        icon: "none",
        duration: 2000
      })
      return false;
    } else {
        // 显示加载图标
        wx.showLoading({
          title: '玩命加载中',
        })
        var shopid = wx.getStorageSync("shop_id");
        var param = {
          url: "api/shop/grabOrders",
          data: {
            shop_id: shopid,
            now_page: now_page,
            type: 4
          },
          success: function (e) {
            that.setData({
              orderlist: that.data.orderlist.concat(e.data.data.list),
              now_page: now_page
            })
            // 隐藏加载框
            wx.hideLoading();

          },
        };
        app.post(param);
        }
  },

})